//显示toast类
class Modal {
  //私有属性
  #modal = uni.showModal

  //显示
  show({confirm, cancel, ...otherConfig}) {
    return new Promise((resolve, reject) => {
      this.#modal({
        cancelText: '取消',
        confirmText: '确定',
        success(res) {
          if (res.confirm) {
            resolve()
          } else if (res.cancel) {
            reject()
          }
        },
        ...otherConfig
      })
    })
  }

  //成功
  info(content) {
    return this.show({title: '提示', content})
  }

  //失败
  danger(content) {
    return this.show({title: '警告', content})
  }
}

//创建toast实例
const modal = new Modal()

export default modal
